package com.lm.scau.framedemos.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lm.scau.framedemos.BaseActivity;
import com.lm.scau.framedemos.R;

import java.util.List;

/**
 * Function:
 * auth：liming on 2016/5/25 15:33
 * mail：liming@wxchina.com
 */
public class MainAdapter extends BaseAdapter {
    private BaseActivity mAvtivity;
    private LayoutInflater mInflater;
    private List<String> titles;
    private List<String> subTitles;

    public MainAdapter(List<String> titles, List<String> subTitles, BaseActivity avtivity) {
        this.mAvtivity = avtivity;
        mInflater = LayoutInflater.from(mAvtivity);
        this.titles = titles;
        this.subTitles = subTitles;
    }

    @Override
    public int getCount() {
        return titles.size();
    }

    @Override
    public Object getItem(int position) {
        return new Object[]{titles.get(position), subTitles.get(position)};
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        viewHolder holder = null;
        if (null == convertView) {
            holder = new viewHolder();
            convertView = mInflater.inflate(R.layout.item_main_list, parent, false);
            holder.icon = (ImageView) convertView.findViewById(R.id.icon_img);
            holder.head = (TextView) convertView.findViewById(R.id.head_text_view);
            holder.subHead = (TextView) convertView.findViewById(R.id.sub_head_text_view);
            convertView.setTag(holder);
        } else {
            holder = (viewHolder) convertView.getTag();
        }
        holder.icon.setImageResource(R.drawable.ic_main_list);
        holder.head.setText(titles.get(position));
        holder.subHead.setText(subTitles.get(position));
        return convertView;
    }

    class viewHolder {
        public ImageView icon;
        public TextView head;
        public TextView subHead;
    }
}
